package sk.stuba.fiit.pki.ws.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;

import sk.stuba.fiit.pki.service.PkiService;
import sk.stuba.fiit.pki.ws.schema.beans.CrlRequest;
import sk.stuba.fiit.pki.ws.schema.beans.CrlResponse;
import sk.stuba.fiit.pki.ws.service.CommUtil;
import sk.stuba.fiit.pki.ws.service.MarshalingCRLService;

@Endpoint
public class CrlEndpoint implements MarshalingCRLService{

	@Autowired
	PkiService pkiService;
	
	 @PayloadRoot(localPart=CRL_REQUEST, namespace=NAMESPACE)
	public CrlResponse getCRL(CrlRequest request) {
		CrlResponse crlResponse = new CrlResponse();
		try{
			 byte[] resp = pkiService.getActualCRL(request);
			 crlResponse.withCrlresp(CommUtil.getInstance().codeBase64ByteToString(resp));
			 return crlResponse;
		}catch(Exception e){
			e.printStackTrace();
		}
		return new CrlResponse();
	}
	 
	 

}
